/**
 * 
 */
package id.web.faisalabdillah.xtimesheet.services.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.appengine.api.datastore.Key;

import id.web.faisalabdillah.xtimesheet.dao.ITimeSheetDao;
import id.web.faisalabdillah.xtimesheet.domain.TimeSheet;
import id.web.faisalabdillah.xtimesheet.services.ITimeSheetService;

/**
 * @author Muhamad Faisal Abdillah
 *
 */
@Service
@Transactional(readOnly=true)
public class TimeSheetServiceImpl implements ITimeSheetService {
	@Autowired
	private ITimeSheetDao timeSheetDao;
	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#insert(id.web.faisalabdillah.xtimesheet.domain.TimeSheet)
	 */
	@Override
	@Transactional(readOnly=false)
	public boolean insert(TimeSheet object) {
		try {
			timeSheetDao.insert(object);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#update(id.web.faisalabdillah.xtimesheet.domain.TimeSheet)
	 */
	@Override
	@Transactional(readOnly=false)
	public boolean update(TimeSheet object) {
		try {
			timeSheetDao.update(object);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#delet(long)
	 */
	@Override
	@Transactional(readOnly=false)
	public boolean delete(Key id) {
		try {
			timeSheetDao.delete(findById(id));
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#findById(long)
	 */
	@Override
	public TimeSheet findById(Key id) {
		return timeSheetDao.findById(id);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#listAll()
	 */
	@Override
	public List<TimeSheet> listAll() {
		// TODO Auto-generated method stub
		return timeSheetDao.listAll();
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#listPaging(int, int)
	 */
	@Override
	public List<TimeSheet> listPaging(int firstRow, int maxRow) {
		// TODO Auto-generated method stub
		return timeSheetDao.listPaging(firstRow, maxRow);
	}

	/* (non-Javadoc)
	 * @see id.web.faisalabdillah.xtimesheet.services.ITimeSheetService#findByDate(java.util.Date)
	 */
	@Override
	public TimeSheet findByDate(Date date) {
		return timeSheetDao.findByDate(date);
	}

}
